#pragma once
#include <nodes\DynamicSpriteNode.h>
#include "lib\container\GridArray.h"
#include "Gutter.h"
#include "ParticleSystem.h"

class Map : public ds::DynamicSpriteNode {

struct Entry {
	ds::Sprite* sprite;
	int color;
	bool marked;
	float timer;
};

public:
	Map(Gutter* gutter);
	~Map(void);
	void update( float elapsed );
	bool addBlock(const ds::Vec2& pos,int firstColor,int secondColor,int thirdColor,int fourthColor);
	void cleanMarkedBlocks();
	int cleanRow(int row);
	void reset();
private:
	int checkSurrounding(int xp,int yp);
	void check(int xp,int yp,int lastDir,std::vector<ds::Vec2> *list,bool rec);
	void markBlocks();
	void markSingleBlock(int gx,int gy);
	bool markSingleEntry(int gx,int gy);
	void addEntry(int gx,int gy,int color);
	bool isBlockAvailable(int gx,int gy);
	bool isFree(int gx,int gy);
	bool isCoherent(int gx,int gy);
	//
	ds::GridArray<Entry>* m_Grid;
	float m_CleanTimer;
	Gutter* m_Gutter;
	BlockEmitter* m_Emitter;
};

